package com.zycfc.zsf.boot.core.common;

import org.springframework.context.*;
import org.springframework.beans.*;

public class SpringContextHelper implements ApplicationContextAware
{
    private static ApplicationContext applicationContext;
    
    public void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
        SpringContextHelper.applicationContext = applicationContext;
    }
    
    public static ApplicationContext getApplicationContext() {
        return SpringContextHelper.applicationContext;
    }
    
    public static Object getBean(final String name) {
        return getApplicationContext().getBean(name);
    }
    
    public static <T> T getBean(final Class<T> clazz) {
        return (T)getApplicationContext().getBean((Class)clazz);
    }
    
    public static <T> T getBean(final String name, final Class<T> clazz) {
        return (T)getApplicationContext().getBean(name, (Class)clazz);
    }
}
